<template>
  <div id="configure">
    <div class="homeTitle">配置栏目权限</div>
    <div class="bottomTable">
      <div class="table">
        <table>
          <tr>
            <td>已赋权角色编号</td>
            <td>已赋权角色名称</td>
            <td>操作</td>
          </tr>
          <tr v-for="(item, index) in tableBottom" :key="index">
            <td>{{item.id}}</td>
            <td>{{item.name}}</td>
            <td>
              <el-button type="primary" size="small" @click="del(item)">删除</el-button>
            </td>
          </tr>
          <tr>
            <td style="background: #EEEDE2; color: black;">拟赋权角色</td>
            <td style="background: #EEEDE2;">
              <el-select v-model="value" placeholder="请选择">
                <el-option
                  v-for="item in options"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id">
                </el-option>
              </el-select>
            </td>
            <td style="background: #EEEDE2;"><el-button type="primary" size="small" @click="add">添加</el-button></td>
          </tr>
        </table>
      </div>
    </div>
    <div class="btn">
      <el-button type="primary" size="small" @click="close">关闭</el-button>
    </div>
  </div>
</template>

<script>
export default {
  name: "configure",
  data() {
    return {
     tableBottom: [],
      juese: '',
      desc: '' ,
      options: [],
        value: ''
    };
  },
  mounted () {
    this.getdata();
    this.getjuese();
  },
  methods: {
    getdata () {
      this.axios.get('roleMenu/findRoleByMid',{params:{menuId: this.$route.query.id}})
        .then(({data})=> {
          if (data.code == 200) {
            this.tableBottom = data.data;
          }
        })
    },
    getjuese () {
      this.axios.get('roleMenu/findNotEmpowerment',{params:{menuId: this.$route.query.id}})
        .then(({data})=> {
          if (data.code == 200) {
            this.options = data.data;
            parseInt
          }
        })
    },
    del (item) {
      this.axios.post('roleMenu/deleteById',{menuId: parseInt(this.$route.query.id), roleId: item.id})
        .then(({data})=> {
          if (data.code == 200) {
            this.$message({message: '删除成功',type: 'success'});
            this.getdata();
          }
        })
    },
    close () {
      this.$router.go(-1);
    },
    add () {
      if(!this.value) {
        this.$message({message: '请选择拟赋权角色',type: 'warning'});
      } else {
        this.axios.post('roleMenu/add',{menuId: this.$route.query.id, roleId: this.value.toString()})
          .then(({data})=> {
            if (data.code == 200) {
              this.$message({message: '添加成功',type: 'success'});
              this.getdata();
            }
          })
      }
    }
  }
};
</script>

<style lang="scss">
#configure {
  .bottomTable {
    margin-top: 30px;
    table {
      border: 1px solid white;
      width: 100%;
      border-collapse: collapse;
      tr {
        &:first-child {
          background-color: #181c1d !important;
          color: white;
          td {
            background-color: #181c1d !important;
          }
        }
        td {
          text-align: center;
          padding: 5px 10px;
          border-right: 1px solid white;
          border-bottom: 1px solid white;
          color: white;
          background: #2c3135;
          .el-select {
            width: 100%;
          }
        }
      }
    }
    .addwhite {
      height: 46px;
      background-color: white;
      padding: 0 20px;
      span {
        color: #cccccc;
        line-height: 46px;
      }
    }
  }
  .btn {
    margin-top: 20px;
    margin-bottom: 20px;
    text-align: center;
    .el-button {
    }
  }
}
</style>
